<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class TiyanController extends CommonController {

    
    
  //===================================产品订单
    public function index() {

         $s=M('tiyan');
           $count=$s->count();
        $Page =new \Think\Page($count,10);
        $Page -> setConfig('first','首页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('prev','上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');

        $show1 = $Page->show();

        $show=$s->order("id desc")->limit($Page->firstRow, $Page->listRows)->select();



        foreach ($show as &$value) {
         $value['title']=mb_substr(strip_tags(htmlspecialchars_decode($value['title'])),0,20,'utf-8');
         
         }

 
        
 $this->assign('page',$show1);
          $this->assign('show',$show);

            $this->display();
    }
      
  
    public function addshow(){
        $sh=M('tiyan');
        $shi=$sh->select();
        $this->assign('shi',$shi);


        if(IS_POST){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["img"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }

                $data['address']=I('post.sheng').I('post.shi').I('post.qu').I('post.address');
                $data['title']=I('post.title');
                 $data['phone']=I('post.phone');
                

            if(M('tiyan')->add($data)){

                $this->success('添加体验门店成功',U('Tiyan/index'));
                exit();
                }else{
                $this->success('添加体验门店失败',U('Tiyan/index'));
                exit();
            }
         
        }

        $this->display();
        


    }


   




    public function update(){

        if (I('get.id')) {
            $id=I('get.id');
        }else{
            $id=$_POST['dd'];
        }

            $xinxi=M('tiyan')->where('id='.$id)->find();
            $this->assign('xinxi',$xinxi);
  
   

  
        if(IS_POST){
            if ($xinxi['img']) {

                unlink("/Uploads/".$xinxi['img']); 
     //删除图片文件
            }

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     5145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();

           $data['title']=I('post.title');
           $data['phone']=I('post.phone');
           $data['address']=I('post.address');
          
            if(!$info) {// 上传错误提示错误信息
               
                unset( $data["img"]);
            }else{// 上传成功
                $data["img"]=$info["pic"]["savepath"].$info["pic"]["savename"];

            
            }

            

            if(M('tiyan')->where("id=".$id)->save($data)){

                $this->success('体验门店修改成功',U('Tiyan/index'));
                exit();
            }else{
                $this->success('体验门店修改失败',U('Tiyan/index'));
                exit();
            }

        
        }else{
            $this->display(); 
        }

 
    }


    public function del(){

        $ids = $_POST['id'];

        $str="('".implode("','",$ids)."')";
      

        if (M("tiyan")->where("id in ".$str)->delete()) {
            
            $this->success('删除成功');
        } else {
            $this->success('删除失败');
        }
    }

 public function yuyue(){
     
     $m=M('yuyue');

 $count=$m->count();
        $Page =new \Think\Page($count,20);
        $Page -> setConfig('first','首页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('prev','上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');

        $show1 = $Page->show();

        $yuyue=$m->order("id desc")->limit($Page->firstRow, $Page->listRows)->select();




     $this->assign('page',$show1);
    $this->assign('yuyue',$yuyue);



     




    $this->display();

 }



public function zhanshi(){


       $s=M('tylunbo');
        $show=$s->order("id desc")->select();

          $this->assign('show',$show);





    $this->display();
}

public function gengxin(){


        if (I('get.id')) {
            $id=I('get.id');
        }else{
            $id=$_POST['dd'];
        }

            $xinxi=M('tylunbo')->where('id='.$id)->find();
            $this->assign('xinxi',$xinxi);
  
   

  
        if(IS_POST){
            if ($xinxi['img']) {

                unlink("/Uploads/".$xinxi['img']); 
     //删除图片文件
            }

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     5145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();

    
          
            if(!$info) {// 上传错误提示错误信息
               
                unset( $data["pic"]);
            }else{// 上传成功
                $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];

            
            }

            

            if(M('tylunbo')->where("id=".$id)->save($data)){

                $this->success('轮播图修改成功',U('Tiyan/zhanshi'));
                exit();
            }else{
                $this->success('轮播图修改失败',U('Tiyan/zhanshi'));
                exit();
            }

        
        }else{
            $this->display(); 
        }




}



    public function delyu(){

        $ids = $_POST['id'];

        $str="('".implode("','",$ids)."')";
      

        if (M("yuyue")->where("id in ".$str)->delete()) {
            
            $this->success('删除成功');
        } else {
            $this->success('删除失败');
        }
    }




    public function dell(){

        $ids = $_POST['id'];

        $str="('".implode("','",$ids)."')";
      

        if (M("tylunbo")->where("id in ".$str)->delete()) {
            
            $this->success('删除成功');
        } else {
            $this->success('删除失败');
        }
    }

public function lunbo(){


        if(IS_POST){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }

                

            if(M('tylunbo')->add($data)){

                $this->success('添加轮播图成功',U('Tiyan/zhanshi'));
                exit();
                }else{
                $this->success('添加轮播图失败',U('Tiyan/zhanshi'));
                exit();
            }
         
        }


    $this->display();
}






}

?>